package org.hales.common;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.List;
import java.util.Map;

public class Enum {
    @Getter
    @AllArgsConstructor
    public enum ValidCheckCodeResultType {
        Success(0, "验证码正确"),
        CheckCodeWrong(1, "验证码错误"),
        CheckCodeExpire(2, "验证码过期"),
        CheckCodeRequire(3, "验证码必填");

        private int code;
        private String desc;
    }

    /**
     * 返回结果类型
     */
    public enum ResponseCode {
        SUCCESS(0, "成功"),
        ERROR(1, "错误"),
        UNKNOWN_ERROR(10, "未知错误"),
        NEED_LOGIN(20, "需要登录"),
        PERMISSION_DENIED(30, "权限不足"),
        ILLEGAL_ARGUMENT(40, "参数错误");

        private final int code;
        private final String desc;

        ResponseCode(int code, String desc) {
            this.code = code;
            this.desc = desc;
        }

        public int getCode() {
            return code;
        }

        public String getDesc() {
            return desc;
        }
    }


    /**
     * 异常类型
     */
    public enum ExceptionType {
        SQL_EXCEPTION(0, "sql异常"),
        IO_EXCEPTION(1, "io异常"),
        RUNTIME_EXCEPTION(2, "runtime异常"); //默认异常类型

        private final int code;
        private final String desc;

        ExceptionType(int code, String desc) {
            this.code = code;
            this.desc = desc;
        }

        public int getCode() {
            return code;
        }

        public String getDesc() {
            return desc;
        }
    }


    /**
     * 日志类型
     */
    public enum LogType {
        UNKNOWN(-1, "未知"),
        SUCCESS(1, "成功"), //操作成功
        FAIL(2, "失败"), //操作失败，如Key、ID索引查找失败等
        ERROR(3, "错误"), //操作过程发生错误，如输入参数不正确、枚举类型未知、错误调用基类函数等
        EXCEPTION(4, "异常"), //捕捉到程序异常
        INFO(5, "信息"); //仅为记录信息

        private int code;
        private String desc;

        LogType(int code, String desc) {
            this.code = code;
            this.desc = desc;
        }

        public int getCode() {
            return code;
        }

        public String getDesc() {
            return desc;
        }
    }


    /**
     * 密码强度
     */
    public enum PasswordStrength {
        INVALID(0, "无效密码"),
        WEAK(1, "低强度密码"),
        NORMAL(2, "中强度密码"),
        STRONG(3, "高强度密码");

        private final Integer code;
        private final String desc;

        PasswordStrength(Integer code, String desc) {
            this.code = code;
            this.desc = desc;
        }

        public Integer getCode() {
            return code;
        }

        public String getDesc() {
            return desc;
        }

        public static PasswordStrength getPasswordStrength(Integer code) {
            for (PasswordStrength passwordStrength : values()) {
                if (passwordStrength.getCode().equals(code)) {
                    return passwordStrength;
                }
            }
            return null;
        }
    }


    /**
     * 启用状态
     */
    public enum Active {
        ENABLE(1, "启用"),
        DISABLE(0, "禁用");

        private final Integer code;
        private final String desc;

        Active(Integer code, String desc) {
            this.code = code;
            this.desc = desc;
        }

        public Integer getCode() {
            return code;
        }

        public String getDesc() {
            return desc;
        }

        public static Active getActive(Integer code) {
            for (Active active : values()) {
                if (active.getCode().equals(code)) {
                    return active;
                }
            }
            return null;
        }
    }


    /**
     * 用户类型
     */
    public enum UserType {
        SYSTEM_ADMIN(101, "系统管理员"),
        ENTERPRISE(201, "企业用户"),
        PROVINCE_ADMIN(301, "省级管理用户"),
        CITY_ADMIN(401, "地级管理用户"),
        COUNTY_ADMIN(501, "县级管理用户");

        private Integer code;
        private String desc;

        UserType(Integer code, String desc) {
            this.code = code;
            this.desc = desc;
        }

        public Integer getCode() {
            return code;
        }

        public String getDesc() {
            return desc;
        }

        public static UserType getUserType(Integer code) {
            for (UserType userType : values()) {
                if (userType.getCode().equals(code)) {
                    return userType;
                }
            }
            return null;
        }

        public static List<Map> getAllUserType() {
            List<Map> mapList = Lists.newArrayList();
            Map map;
            for (UserType userType : values()) {
                map = Maps.newHashMap();
                map.put("code", userType.getCode());
                map.put("desc", userType.getDesc());
                mapList.add(map);
            }
            return mapList;
        }
    }


    /**
     * 行政区划级别
     */
    public enum DistrictLevel {
        UNKNOWN(-1, "未指定"),
        NATION(0, "国家、中央"),
        PROVINCE(1, "省、自治区、直辖市、特别行政区"),
        CITY(2, "地市、州、盟"),
        COUNTY(3, "县、区、旗"),
        TOWN(4, "乡、镇、街道"),
        VILLAGE(5, "村、居委会");

        private final Integer code;
        private final String desc;

        DistrictLevel(Integer code, String desc) {
            this.code = code;
            this.desc = desc;
        }

        public Integer getCode() {
            return code;
        }

        public String getDesc() {
            return desc;
        }

        public static DistrictLevel getDistrictLevel(Integer code) {
            for (DistrictLevel districtLevel : DistrictLevel.values()) {
                if (districtLevel.getCode().equals(code)) {
                    return districtLevel;
                }
            }
            return null;
        }
    }


    /**
     * 新闻布局类型
     */
    public enum LayoutType {
        UNKNOWN(-1, "未指定"),
        TEXT(1, "无图"),
        TEXT_IMAGE1(2, "单图"),
        TEXT_IMAGE3(3, "三联图");

        private final Integer code;
        private final String desc;

        LayoutType(Integer code, String desc) {
            this.code = code;
            this.desc = desc;
        }

        public Integer getCode() {
            return code;
        }

        public String getDesc() {
            return desc;
        }

        public static LayoutType getLayoutType(Integer code) {
            for (LayoutType layoutType : LayoutType.values()) {
                if (layoutType.getCode().equals(code)) {
                    return layoutType;
                }
            }
            return null;
        }
    }


    /*
     * 水、气站数据的达标不达标状态
     * */
    public enum Compliance {
        YES("1", "达标"),
        NO("0", "超标"),
        OTHER("-", "其他");

        private final String code;
        private final String desc;

        Compliance(String code, String desc) {
            this.code = code;
            this.desc = desc;
        }

        public String getCode() {
            return code;
        }

        public String getDesc() {
            return desc;
        }

        public static Compliance getCompliance(String code) {
            for (Compliance active : values()) {
                if (active.getCode().equals(code)) {
                    return active;
                }
            }
            return null;
        }
    }

    /**
     * 职工职位类型
     */
    public enum Position {
        经办人(1, "经办人"),
        部门负责人(2, "部门负责人"),
        分管领导(3, "分管领导");


        private final int code;
        private final String desc;

        Position(int code, String desc) {
            this.code = code;
            this.desc = desc;
        }

        public int getCode() {
            return code;
        }

        public String getDesc() {
            return desc;
        }
    }

    /**
     * 执法局职工职位类型
     */
    public enum ZFPosition {
        经办人(1, "经办人"),
        部门负责人1(2, "部门负责人1"),
        部门负责人2(3, "部门负责人2"),
        执法局分管领导(4, "执法局分管领导");


        private final int code;
        private final String desc;

        ZFPosition(int code, String desc) {
            this.code = code;
            this.desc = desc;
        }

        public int getCode() {
            return code;
        }

        public String getDesc() {
            return desc;
        }
    }

    /**
     * 部门类型
     */
    public enum DepartmentID {
        执法局("362", "(旧)执法局"),
        监测站("363", "监测站"),
        综合科("378", "综合科"),
        污防科("379", "污防科"),
        太湖办("380","太湖办"),
        新执法局("383","执法局");

        private final String code;
        private final String desc;

        DepartmentID(String code, String desc) {
            this.code = code;
            this.desc = desc;
        }

        public String getCode() {
            return code;
        }

        public String getDesc() {
            return desc;
        }
    }
}
